﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeTester
{
    class ArraySearch
    {
        /// <summary>
        /// 二维数组，左到右按小到大，上到下按小到大 有序，查询给出的数是否在数组中
        /// </summary>
        /// <param name="matrix"></param>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <param name="searchValue"></param>
        /// <returns></returns>
        public bool Search(int[,] matrix, int rows, int columns, int searchValue)
        {

            int row = 0;
            int column = columns - 1;

            while (row < rows && column >= 0)
            {
                if (matrix[row, column] == searchValue)
                    return true;

                if (matrix[row, column] > searchValue)
                    column--;

                if (matrix[row, column] < searchValue)
                    row++;
            }

            return false;
        }

    }
}
